package com.itheima1.log;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class Test1 {
    @Pointcut("execution(* com.itheima1.service.impl.*.*(..))")
    private void pt1(){}
    /**
     *@Before("pt1()")
     */
    public void beforeMe(){
        System.out.println("准备转账");
    }
    public void afterReturn(){
        System.out.println("转账完成");
    }
    public void throwMe(){
        System.out.println("转账出错");
    }
    @Around("pt1()")
    public Object around(ProceedingJoinPoint pro){
        Object proceed=null;
        try {
            Object[] args = pro.getArgs();
            System.out.println("开始转账");
            proceed = pro.proceed();
            System.out.println("转账完成");
            return proceed;
        } catch (Exception e) {
            System.out.println("转账出错");
            e.printStackTrace();
        } finally {
            System.out.println("最终输出");
            return proceed;
        }
    }
}
